package com.yhd.admin.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yhd.admin.bean.RoleMenuPriv;
import com.yhd.admin.mapper.RoleMenuPrivMapper;
import com.yhd.admin.utils.StringUtils;
@Service
public class RoleMenuPrivServiceImpl implements RoleMenuPrivService {
	@Autowired
	private RoleMenuPrivMapper roleMenuPrivMapper;
	
	@Override
	public List<RoleMenuPriv> getRoleMenuPrivByRoleId(int roleId) {
		return roleMenuPrivMapper.selectRoleMenuPrivByRoleId(roleId);
	}

	@Override
	public void deleteRoleMenuPrivByRoleId(int roleId) {
		roleMenuPrivMapper.deleteRoleMenuPrivByRoleId(roleId);
	}

	/**
	 * 先删除原来的权限，在批量添加新的权限
	 */
	@Override
	public void addRoleMenuPriv(int roleId, String menuIds) {
		roleMenuPrivMapper.deleteRoleMenuPrivByRoleId(roleId);
		//批量添加
		if(!StringUtils.isEmpty(menuIds)){
			String[] ids = menuIds.split(",");
			for(String id : ids){
				RoleMenuPriv rmp = new RoleMenuPriv();
				rmp.setRole_id(roleId);
				rmp.setMenu_id(StringUtils.convertInt(id));
				roleMenuPrivMapper.addRoleMenuPriv(rmp);
			}
		}
	}

}
